*************************************************************************
*																		*
*					Campaign Panel Book Chapter 5 - Transformation Long Format				*
*																		*
*************************************************************************	


use "${data}\ZA5305_en_v5-0-0.dta", clear

keep lfdn teilnahme w1

cd "${path}\Reproducible Do-Files\Chapter 5\Data"

// Addition of operationalized variables
merge 1:1 lfdn using mobilization09
drop _merge

merge 1:1 lfdn using komm_variablen09
drop _merge

merge 1:1 lfdn using koginvolv09
drop _merge

merge 1:1 lfdn using attitudes09
drop _merge

*--------------------------------------
* Transform into long format
*---------------------------------------

reshape long wwbt watcheddebate gesprhin pk_gesamtino ///
	pr_bild i_nupol ///
	pr_paper pr_andz tv_oeff tv_privat m_gesamti ///
	wkampfint intefficacy extefficacy zufr ///
	indiff entfremda, i(lfdn) j(welle) 

	
*------------------------------------------------------------------
* Adjustment of all values by personal mean value
*-------------------------------------------------------------------
		
foreach var in wwbt watcheddebate gesprhin pk_gesamtino ///
	pr_bild i_nupol ///
	pr_paper pr_andz tv_oeff tv_privat m_gesamti ///
	wkampfint intefficacy extefficacy zufr ///
	indiff entfremda  {

   bysort lfdn: egen mean_`var'=mean(`var') 
   gen d_`var'=`var'-mean_`var'
   drop mean_`var'
}
	
	
*-------------------------------
* Wave dummies
*-------------------------------

rename w1 teil_w1
tab welle, gen(w)	
	
	
save "${path}\Reproducible Do-Files\Chapter 5\Data\longformat09.dta", replace
	